// const sql = require('mssql');
var {Sequelize,DataTypes} = require("sequelize");
let { dboption } = require("../conf");

const sequelize = new Sequelize(dboption);

var project = require('../models/base_conpermit_project')(sequelize, DataTypes);
var project_expand = require('../models/base_consproject')(sequelize, DataTypes);

//sequelize-auto -o "./models" -h 60.211.159.133 -p 8090 -d zj_cycle  -u sa -x Hxy971123 -e mssql -t base_conpermit_project
//npm install -g mssql tedious
(async () => {
    try {
        // make sure that any items are correctly URL encoded in the connection string
        // await sql.connect('Server=60.211.159.133,8090;Database=zj_cycle;User Id=sa;Password=Hxy971123;trustServerCertificate=true;')
        // const result = await sql.query `select top 1 * from base_conpermit_project`;
        // result.recordset.forEach(row => {
        // })
        // const res = await model.findAll({where:{id:{ [Op.lte]: 2}}});
        const res = await project.findAll();
        res.forEach(async row => {
            let ins = row.toJSON();
            delete ins.id;
            if(ins['招投标系统中查询'].length>10 ) {
                let codes = ins['招投标系统中查询'].replace(/；/g,';').split(';');
                codes.forEach(async (code)=>{
                    ins['招投标系统中查询'] = code;
                    await project_expand.create(ins);
                })
            }
            else{
                await project_expand.create(ins); 
            }
        });

    } catch (err) {
        console.log('异常', err.toString())
    }
})()